package com.作业.Day5;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;

import java.util.Scanner;

public class Homework4 {
    public static void main(String[] args) {
        Admin admin = new Admin();
        adminSystem adminSystem = new adminSystem();
        adminSystem.first();
        Scanner scanner = new Scanner(System.in);
        //输入选择目录
        System.out.print("请选择，输入数字:");
        int num = scanner.nextInt();
        //判断选择
        if (num == 1) {
            //判断登录
            while (true) {
                System.out.print("请输入用户名:");
                admin.setName(scanner.next());
                System.out.print("请输入密码:");
                admin.setPassword(scanner.next());
                boolean result = adminSystem.login(admin);
                if (result) {
                    adminSystem.second();
                    System.out.println();
                    break;
                }


            }
        } else if (num == 2) {
            while (true) {
                System.out.print("请输入用户名:");
                admin.setName(scanner.next());
                System.out.print("请输入密码:");
                admin.setPassword(scanner.next());
                boolean result = adminSystem.login(admin);
                if (result) {
                    Admin newAdmin = new Admin();
                    System.out.print("请输入新用户名:");
                    newAdmin.setName(scanner.next());
                    System.out.print("请输入新密码:");
                    String p1 = scanner.next();
                    System.out.print("请输再次输入密码:");
                    String p2 = scanner.next();
                    if (p1.equals(p2)) {
                        newAdmin.setName(p2);
                        System.out.println("用户密码已经改了");
                        adminSystem.second();
                        break;
                    } else
                        System.out.println("确认失败，请重新验证");
                }
            }
        } else if (num == 3) {
            return;
        }
        Customer[] customers = {
                new Customer("1900", "100", "1999"),
                new Customer("1900", "100", "1999"),
                new Customer("1900", "100", "1999"),
                new Customer("1900", "100", "1999"),
                new Customer("1900", "100", "1999"),
                new Customer("1900", "100", "1999"),
                new Customer("1900", "100", "1999"),
                new Customer("1900", "100", "1999"),
                new Customer("1900", "100", "1999"),

        };
        while (true) {
            //二级目录
            System.out.print("请选择，输入数字:");
            int i = scanner.nextInt();
            String catalog2;
           adminSystem.extracted(i);

            //三级目录
            System.out.print("请选择，输入数字:或按'n'返回上机一级菜单:");
            String next = scanner.next();
            switch (next) {
                case "1":
                    adminSystem.show(customers);
                    break;
                case "2":
                    break;
                case "3":
                    break;
                case "n":
                    adminSystem.second();
                    continue;

            }
        }


    }


}

/**
 * 管理类
 */
@Data
@NonNull
class Admin {
    private String name;
    private String password;
}

/**
 * 客户类
 */
@Data
@AllArgsConstructor
@NonNull
class Customer {
    String member;
    String birth;
    String integrate;


}

/**
 * 系统
 */
class adminSystem {
    /**
     * 目录
     */
    void first() {
        System.out.println();
        System.out.println("欢迎使用我行我素购物管理系统");
        System.out.println("******************************");
        System.out.println("1.登 录 系 统");
        System.out.println("2.更改管理员密码");
        System.out.println("3.退出");
        System.out.println("******************************");
    }


    /**
     * 登录功能
     */
    boolean login(Admin admin) {
        if (admin.getName().equals("manage") && admin.getPassword().equals("0000")) {
            System.out.println("输入正确 ");
            return true;
        } else {
            System.out.println("用户名和密码不匹配，请重新输入");

            return false;
        }

    }


    /**
     * 二级目录
     */
    void second() {
        System.out.println();
        System.out.println("欢迎使用我行我素购物管理系统");
        System.out.println("******************************");
        System.out.println("1.客户信息管理");
        System.out.println("2.购物结算");
        System.out.println("3.真情回馈");
        System.out.println("4.注销");
        System.out.println("******************************");
    }

    /**
     * 选择目录
     * @param i
     */
    void extracted(int i) {
        String catalog2;
        switch (i) {
            case 1:
                catalog2 = "客户信息管理";
                System.out.println("我行我素购物管理系统>" + catalog2);
                third();
                break;
            case 2:
                catalog2 = "购物结算";
                System.out.println("我行我素购物管理系统>" + catalog2);
                break;
            case 3:
                catalog2 = "真情回馈";
                System.out.println("我行我素购物管理系统>" + catalog2);
                break;
            case 4:
                catalog2 = "注销";
                System.out.println("我行我素购物管理系统>" + catalog2);
                break;
        }
    }

    /**
     * 三级目录
     */
    void third() {
        System.out.println();
        System.out.println("******************************");
        System.out.println("1.显 示 所 有 客 户 信 息");
        System.out.println("2.添 加 客 户 信 息");
        System.out.println("3.修 改 客 户 信 息");
        System.out.println("4.注 销");
        System.out.println("******************************");
    }

    /**
     * 显示客户信息
     */
    void show(Customer[] customers) {
        System.out.print("会员号");
        System.out.print("生日");
        System.out.print("积分");
        System.out.println("-------------|-------------|-------------");
        for (int i = 0; i < customers.length; i++) {
            System.out.print(customers[i].getMember()+"      ");
            System.out.print(customers[i].getBirth()+"         ");
            System.out.println(customers[i].getIntegrate());

        }
    }

}